<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    let r = 1;
    while (r <= 3) {
        console.log("r = ",r);
        r ++; // r = r + 1
    }

    // 使用while循环，累加1到100
    let sum = 0;
    let count = 1;
    while (count <= 100) {
        sum += count;
        count ++;
    }
    console.log("sum =",sum);

    // 通常while循环用于不定次数的循环，即不太清楚一共要循环多少次的情况
    // while (true)的使用非常多，通常搭配break关键字跳出当前循。
    r = 0;
    while (true) {
        r ++;
        if (r >= 10) {
            break;
        }
        console.log("r = ",r);
    }
</script>
</html>